package com.lark.utils;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.util.Objects;

/**
 * 图片操作工具类
 */
public final class ImageUtil {

    private static final String IMAGE_PATH = "/static/images/";
    private static final String ICON_PATH = "/static/icons/";

    public static ImageView getImageView(String imagePath) {
        return getImageView(imagePath, true);
    }

    public static ImageView getImageView(String imagePath, boolean addDefaultPath) {
        return new ImageView(Objects.requireNonNull(ImageUtil.class.getResource(addDefaultPath ? IMAGE_PATH + imagePath : imagePath)).toExternalForm());
    }

    public static ImageView getImageView(String imagePath, int width, int height) {
        ImageView imageView = getImageView(imagePath);
        imageView.setFitWidth(width);
        imageView.setFitHeight(height);
        return imageView;
    }

    public static Image getImage(String imagePath) {
        return getImage(imagePath, true);
    }

    public static Image getImage(String imagePath, boolean addDefaultPath) {
        return new Image(Objects.requireNonNull(ImageUtil.class.getResource(addDefaultPath ? IMAGE_PATH + imagePath : imagePath)).toExternalForm());
    }

    public static Image getIcon(String imagePath) {
        return getIcon(imagePath, true);
    }

    public static Image getIcon(String imagePath, boolean addDefaultPath) {
        return new Image(Objects.requireNonNull(ImageUtil.class.getResource(addDefaultPath ? ICON_PATH + imagePath : imagePath)).toExternalForm());
    }
}
